package com.zut.controller;

import com.zut.Pojo.Result;
import com.zut.Pojo.UserInfo;
import com.zut.Service.registerService.registerImpl.registerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
* @Author: 无恙
* @Description: 注册接口
* @DateTime:  2023.10.26
*/
@RequestMapping("/user")
@RestController
public class registerController {

    @Autowired
    private registerImpl register;

    @PostMapping("/register")
    public Result register(@RequestBody UserInfo userInfo){
        if(Objects.isNull(userInfo)||userInfo.getPhone().equals("")){
            return Result.builder().desc("数据异常！").code(200).build();
        }

        UserInfo register1 = register.register(userInfo);

        if(Objects.isNull(register1)){
            return Result.builder().desc("手机号已经注册，请登录！").code(200).build();
        }else {
            return Result.builder().desc("注册成功！").data(register1).code(200).build();
        }

    }
}
